<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <h1>第{{currentPage}}页</h1>
    <button v-if="currentPage>1"
      @click="changePage('-')"
    >上一页</button>
    <button v-for="num in 5"
      @click="changePage(num)"
    >{{num}}</button>
    <button v-if="5>currentPage"
      @click="changePage('+')"
    >下一页</button>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <!-- 2.写自己的vue代码 -->
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        currentPage: 1
      },
      methods: {
        changePage(num) {
          // 分页的核心功能：切换页码
          if(num == '+') {
            this.currentPage ++
          }else if(num == '-') {
            this.currentPage --
          }else {
            this.currentPage = num;
          }
        }
      },
    })
  </script>
</body>
</html>